package Day016_字符流_Properties类.demo03_属性集;

import java.io.FileReader;
import java.util.Properties;
import java.util.Set;

/**
 * @author zhangyan
 * @date 2020/5/8 11:25
 */
public class Test2_Properties结合流 {
    public static void main(String[] args) throws Exception {

        //创建Properties对象
        Properties pro = new Properties();

        //调用load方法 关联流对象
        FileReader fr = new FileReader("Demo02\\aaa\\d.txt");
        pro.load(fr);

        //获取pro所有键
        Set<String> keySet = pro.stringPropertyNames();
        //循环遍历 键找值
        for (String key : keySet) {
            String value = pro.getProperty(key);
            System.out.println(key + "," + value);
        }
        fr.close();


        /*
        //创建Properties对象
        Properties pro = new Properties();

        //调用load方法
        FileReader fr = new FileReader("Demo02\\aaa\\d.txt");
        pro.load(fr);

        //获取pro所有键
        Set<String> keySet = pro.stringPropertyNames();

        //循环遍历 键找值  ..迭代器
        for (Iterator<String> it = keys.iterator(); it.hasNext();) {
	            String key = it.next();
	            String value = prop.getProperty(key);
	            System.out.println(key+"---"+value);
           }
         */
    }
}
